import socket
import unittest

from utils import dateTimeUtil
from utils import opensslUtil
from utils.opensslUtil import Sovereign


class MyTestCase(unittest.TestCase):

    def test_p12(self):
        opensslUtil.p12_factory("D:\\python\\OpenSSLUtil\\CA_certificate.cer","D:\\python\\OpenSSLUtil\\CA_private.pem", "123456", "D:\\python\\OpenSSLUtil\\")

    def test_csr(self):
        Sovereign.country_name = "aa"
        Sovereign.province_name = "bb"
        Sovereign.city_name = "cc"
        Sovereign.organization_name = "dd"
        Sovereign.department_name = "ee"
        opensslUtil.csr_sign(Sovereign, "D:\\python\\OpenSSLUtil\\")

    def test_ca(self):
        try:
            ip_address = socket.getaddrinfo("www.equnzhe.com", 80)
            print(ip_address)
            print(ip_address[0][4][0])
        except socket.gaierror as e:
            print(f"Error resolving domain equnzhe.com: {e}")
            return None


    def test_time(self):
        bit = '13'
        time_stamp = dateTimeUtil.now(int(bit))
        if bit == '13':
            time_stamp = round(time_stamp / 1000)
            print("aa" + str(time_stamp))

if __name__ == '__main__':
    unittest.main()
